<?
	class c_hook_controller extends c_base_controller
	{
		function index($args)
		{
			global $mvc;
		
			echo '<form action="'.$this->base_url.'save" method="post">';
			foreach($mvc->hooks as $hook => $receivers )
			{
				echo '<b>'.$hook.'</b><br>';
				echo '<textarea style="width:300px; height:300px" name="_hook_'.$hook.'">';
				foreach($receivers as $receiver)
				{
					echo $receiver."\n";					
				}
				echo '</textarea>';
				echo '<hr>';
			}
			echo '<input type="submit" value="'.$mvc->tr('Save').'"/>';
			echo '</form>';
		}
		
		function save($args)
		{
			global $mvc;

			$mvc->hooks = array();
			$hooks = $mvc->extract_data($_REQUEST, '/^_hook_(.*)$/');
			foreach($hooks as $hook => $receiver)
			{
				//Каждый приемник пишется в отдельной строке.
				$receviers = explode("\n", stripslashes(str_replace("\r\n", "\n", $receiver)));
				// Удаляем пустые строки.
				$receviers = array_diff($receviers, array(''));
				$mvc->hooks[$hook] = $receviers;
			}
			$mvc->save_hooks();
			$mvc->redirect($this->base_url);
		}
	}
?>